<template>
  <div class="container">
    <el-dialog title="预览文章" width="800px" :visible="showPrev" @close="clopre">
      <div class="title">
        <h2>{{formData.title}}</h2>
        <div>
          <span>{{formData.createTime|parseTimeByString}}</span>
          <span>{{username}}</span>
          <span class="el-icon-view"></span>
          <span>{{formData.visits}}</span>
        </div>

        <div class="content" v-html="formData.articleBody"></div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 导入获取文章详情接口
import { detail } from "@/api/hmmm/articles";
export default {
  props: {
    // 控制弹层的显示
    showPrev: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      // 用于存放 接口请求回的数据，填入对应的标签中
      formData: {
        title: "",
        createTime: "",
        visits: "",
        articleBody: ""
      },
      username: "超级管理员"
    };
  },

  methods: {
    // 点击关闭弹层
    clopre() {
      this.$emit("update:showPrev", false);
    },
    // 将后台接口中请求的数据  赋值给 formData
    async detail(row) {
      const { data } = await detail(row);
      console.log(data);

      this.formData = data;
      // console.log(this.formData);
    }
  }
};
</script>

<style scoped lang='scss'>
.title {
  border-bottom: 1px dashed #ccc;
  padding-bottom: 10px;
  h2 {
    padding: 0;
    margin: 0;
  }
  span {
    margin-left: 10px;
    margin-top: 10px;
  }
}
.content {
  background: #f5f5f5;
  padding: 10px;
}
</style>
